package cn.com.dhcc.app.pub.core.job.cmdata;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.base.IocBean;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.consts.AppConst;
import cn.com.dhcc.app.pub.core.consts.AppIocBean;
import cn.com.dhcc.turbo.entity.registry.NodeInfo;
import cn.com.dhcc.turbo.service.exch.cmdata.CmDataExchangeLifecycle;
import cn.com.dhcc.turbo.service.registry.BaseInfoService;

/**
 * 通知数据接收者定时器
 * 该定时器将已经传输到目的节点的数据发送给数据接收系统
 */
public class CmDataRemoteNotifyReciverCronJob extends QuartzJobBean {

	private Logger logger = Log.getLogger(LOGTYPE.QUARTZJOB);

	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		BaseInfoService baseInfoService=(BaseInfoService) CM.getBeanByName(IocBean.BASE_INFO_SERVICEIMPL_BEAN);
		NodeInfo localNode;
		try {
			logger.info("["+AppConst.installIp+"]"+"定时任务CmDataRemoteNotifyReciverCronJob开始执行....");
			localNode = baseInfoService.getCurrentNodeInfo();
			 if (localNode!=null) {//节点初始化后才开始定时任务
				 logger.info("Scheduling>>>>>> Sending data to Remote System...");
					CmDataExchangeLifecycle service = (CmDataExchangeLifecycle) CM.getBeanByName(AppIocBean.CM_DATA_EXCHANGE_LIFECYCLE_BEAN);
					service.notifyReceiver();
			 }
			 logger.info("["+AppConst.installIp+"]"+"定时任务CmDataRemoteNotifyReciverCronJob执行结束....");
		} catch (ServiceException e) {
			logger.error("["+AppConst.installIp+"]"+"定时任务CmDataRemoteNotifyReciverCronJob执行时报错:"+e);
		}
		
	}
}